package com.cy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j//
@SpringBootApplication
public class ProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

    @RefreshScope//告诉spring 一般配置中心数据发生变化
    @RestController
    public class ProviderController{
        @Value("${server.tomcat.threads.max:200}")
        private Integer maxThread;

        @RequestMapping("/provider/doGetMaxThread")
        public String doGetMaxThread(){
            return "server.threads.max is  "+maxThread;
        }


        @Value("${server.port:8080}")
        private String server;

        @Value("${logging.level.com.cy:debug}")
        private  String logLevel;

        @GetMapping("/provider/doGetLogLevel")
        public String doGetLogLevel(){
            log.trace("==log.trace==");//跟踪
            log.debug("==log.debug==");//调试
            log.info("==log.info==");//常规信息
            log.warn("==log.warn==");//警告
            log.error("==log.error==");//错误信息
            return "log level is "+ logLevel;
        }

        @GetMapping("/provider/echo/{msg}")
        public  String deRestEcho1(@PathVariable String msg) throws InterruptedException {
            //Thread.sleep(5000);
            log.info("deRestEcho1 start {}",System.currentTimeMillis());
            return server+"say hello "+msg;
        }
    }
}
